<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8"/>
    <title></title>
    <meta name="renderer" content="webkit"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0"/>
    <link rel="stylesheet" href="/layuiadmin/layui/css/layui.css" media="all"/>
    <link rel="stylesheet" href="/layuiadmin/style/admin.css" media="all"/>
    <style>
        .layui-form-item .layui-input-inline {
            width: 150px;
        }
        .layui-form-label {
            padding: 9px 5px;
            width: auto;
        }
    </style>
</head>
<body>
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-tab layui-tab-brief">
            <ul class="layui-tab-title layui_tab_title">
                <li class="layui-this">背包情况</li>
                <li class=""><a href="{:url('user/ticket',array('uid'=>$uid))}">发放观赛券</a></li>
                <li class=""><a href="{:url('user/give_ticket_log',array('uid'=>$uid))}">观赛券发放记录</a></li>
                <li class=""><a href="{:url('user/used_ticket_log',array('uid'=>$uid))}">观赛券用券记录</a></li>

                <li class=""><a href="{:url('order/user_order',array('uid'=>$uid))}">充值记录</a></li>
                <li class=""><a href="{:url('gift/user_send',array('uid'=>$uid))}">送礼记录</a></li>
                <li class=""><a href="{:url('charge/manual',array('uid'=>$uid))}">人工上分</a></li>
                <li class=""><a href="{:url('user/login_log',array('uid'=>$uid))}">登录日志</a></li>
            </ul>
        </div>
        <div class="layui-form layui-card-header layuiadmin-card-header-auto">
            <form class="layui-form layui-col-space5" id="sbumitForm">
                <div class="layui-form-item">
                    <label class="layui-form-label">类型</label>
                    <div class="layui-input-inline layui-show-xs-block">
                        <select name="type" style="width: 180px;">
                            <option value="">全部</option>
                            <option value="0">普通礼物</option>
                            <option value="1">豪华礼物</option>
                            <option value="2">活动赠送礼物</option>
                            <option value="100">喇叭</option>
                            <option value="101">弹幕</option>
                            <option value="102">坐骑</option>
                            <option value="105">观赛券</option>
                        </select>
                    </div>
                    <div class="layui-inline ">
                        <div class="layui-input-inline">
                            <div class="layui-btn" id="submit" onclick="submitForm()">
                                <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                            </div>
                        </div>
                    </div>
                </div>
            </form>
        </div>
        <div class="layui-card-body">
            <table id="demo" lay-filter="demo"></table>
        </div>
    </div>
</div>

<script src="/layuiadmin/layui/layui.js"></script>
<script>
    layui.config({
        base: "/layuiadmin/", //静态资源所在路径
    }).extend({
        index: "lib/index", //主入口模块
    }).use(["table", 'form'], function () {
        $ = layui.jquery, form = layui.form, table = layui.table;
        //监听搜索
        table.render(tableCont());
    });
    
    function submitForm() {
        layui.table.render(tableCont());
    }
    
    function tableCont() {
        return  {
            elem: '#demo',
            id: '#demo',
            url: '/admin/user/backpack?uid={$uid}&' + $("#sbumitForm").serialize(),
            defaultToolbar: [
                'filter', 'print', {title: '提示', layEvent: 'LAYTABLE_EXCEL', icon: 'layui-icon-table'},
            ],
            page: {
                curr: 1   //默认从第一页开始搜索
            },
            method: "get",
            //where: $("#sbumitForm").serialize(),
            limit: 20,
            limits: [20, 30, 50],
            text: {
                none: '暂无相关数据！'//默认无数据
            },
            response: {
                statusName: 'code',
                statusCode: 0,
                msgName: 'msg',
                countName: 'count',
                dataName: 'list',
            },
            cols: [[ //表头
                {field: 'id', title: 'ID', width: "8%", align: "center",},
                {field: 'product_name', title: '物品名称', width: "15%", align: "center",},
                {field: 'type', title: '属性', width: "10%", align: "center",templet: function (item) {
                        //0-普通礼物 1-豪华礼物 2-活动赠送礼物 100-喇叭 101-弹幕 102-坐骑 103-改名卡 104-体验卡 105-入场券
                        switch (item.type) {
                            case 0:
                                return '普通礼物';
                            case 1:
                                return '豪华礼物';
                            case 2:
                                return '活动赠送礼物';
                            case 100:
                                return '喇叭';
                            case 101:
                                return '弹幕';
                            case 102:
                                return '坐骑';
                            case 105:
                                return '观赛券';
                        }

                        return '-';
                    }
                },
                {field: 'price', title: '单价', width: "12%", align: "center",templet: function (item) {
                        switch (item.type) {
                            case 100:
                            case 101:
                            case 102:
                            case 105:
                                return '-';
                        }

                        return item.price;
                    }
                },
                {field: 'exp_time', title: '剩余时间', width: "15%", align: "center",templet: function (item) {
                        if (item.type != 102) {
                            return '-';
                        }

                        var tempTime = (new Date()).getTime() / 1000;

                        if (tempTime >= item.exp_time) {
                            return '<font color="red">已过期</font>';
                        }


                        var times = item.exp_time - tempTime;     //times 是剩余时间总的秒数

                        var d = parseInt(times / 86400); //天

                        var h = parseInt(times / 60 / 60 % 24);      //计算小时
                        h = h < 10 ? '0' + h : h;


                        var htmlStr = h + "时" ;

                        if (d > 0) {
                            htmlStr = d + '天' + h + "时";
                        }

                        return htmlStr;
                    }
                },
                {field: 'quantity', title: '数量', width: "10%", align: "center",templet: function (item) {
                        if (item.type == 102) {
                            return '1';
                        }

                        return item.quantity - item.used_quantity;
                    }
                },
                {field: 'remark', title: '物品说明',  align: "center",},
            ]],
            done: function (res, curr, count) {
            },
        };
    }

</script>
</body>
</html>
